// pages/company/comintro/comintro.js
const App = getApp()
let AJAX = require("../../../utils/util.js").AJAX
let formatRichText = require('../../../utils/util.js').formatRichText
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH:"",
    companyInfo:'',
    concatInfo:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight
    })
    this.requestCompany()
    this.requestConact()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  requestCompany(){
    let vm =this
    AJAX("companys/detail").then(res=>{
      let _data = res.data
      _data.content = formatRichText(_data.content).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      _data.intro = formatRichText(_data.intro).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      vm.setData({
        companyInfo: _data
      })
    })
  },
  requestConact(){
    let vm =this
    AJAX("contact/list").then(res=>{
      let _data = res.data[0]
      _data.detail = formatRichText(_data.detail).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      _data.intro = formatRichText(_data.intro).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      vm.setData({
        concatInfo: _data
      })
    })
  },
  makeCall(e){
    let _phone = e.currentTarget.dataset.phone
    if(!_phone){return}
    wx.makePhoneCall({
      phoneNumber: _phone,
    })
  },
  toLinkConcat(){
    wx.navigateTo({
      url: '/pages/company/adress/adress',
    })
  },
  toInstruction(){
    wx.navigateTo({
      url: '/pages/company/xingzhishu/xingzhishu',
    })
  },
  toTeam(){
    wx.navigateTo({
      url: '/pages/company/teamwork/teamwork',
    })
  },
  navBack(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  }
})